<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>明日新闻</title>
	<link rel="stylesheet" type="text/css" href="../style/css/front/public.css">
	<script src="../style/js/jquery-1.8.3.js" type="text/javascript"></script>
	<script src="../style/js/ajaxfileupload.js"></script>
	<script type="text/javascript">
		$(function () {
			var userId = window.sessionStorage.getItem("userId");
			var userNickName = window.sessionStorage.getItem("userNickName");
			var userNewFileName = window.sessionStorage.getItem("userNewFiLeName");

			// 显示登录/用户账号/头像
			if (userNewFileName != undefined) {
				var imgUrl = "http://127.0.0.1:8080/tomorrowNewsFiles/user/" + userId + "/" + userNewFileName
				document.getElementById("userMsg").innerHTML = "<a href='../user/member/user_center.html'><img  src=" + imgUrl + " style='border-radius:30px' height='60' width='60'></a>"
			} else if (userNickName !== null) {
				$("#userMsg").html("<a href='../user/member/menuber_center.html'>" + userNickName + "</a>");
			}


			$.get("../webmsg/webmsg", function (res) {
				if (res.code == 201) {
					alert("失败")
				} else if (res.code == 500) {
					alert("服务器忙");
				} else {
					$("#logo1").html("<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/logo/" + res.data.logoName + "' width='200' height='90'/>");
					var str = "";
					str += "<p>" + '© ' + (new Date(res.data.operateTime).getFullYear()) + "&nbsp" + res.data.webName + "&nbsp" + '备案号' + "&nbsp" + res.data.recordNum + '号' + "</p>"
					str += "<p>" + '联系电话: ' + res.data.phone + "</p>";
					str += "<p>" + '公司名称: ' + res.data.companyName + "&nbsp" + "&nbsp" + "&nbsp" + "<a href='../back/admin_login.html'>管理员登录</a>" + "&nbsp" + "&nbsp" + "<a href='upload.html'>更换logo</a>" + "</p>";
				}
				$("#webmsg").html(str);
				var filename = window.sessionStorage.getItem("filename");
				var id = window.sessionStorage.getItem("id");
			}, "json");

			//最新推荐
			$.get("../webmsg/newnewstypeid", function (res7) {
				console.log(res7.data)
				if (res7.code == 201) {
					alert("失败")
				} else if (res7.code == 500) {
					alert("服务器忙");
				} else {
					$("#type").html("最新推荐")
					var str = "";
					for (i = 0; i < res7.data.length; i++) {
						str += "<div class=\"lista\">"
						str += "<h3>";
						str += "<a href='javaScript:void(0)' onclick='newscont(" + res7.data[i].id + ")' id='title'>" + res7.data[i].title + "</a>"
						str += "</h3>";
						str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
						str += "<b>" + res7.data[i].publishTime + "</b>"
						str += " </div><div class=\"art_summary\">";
						str += "<p>" + res7.data[i].summary + "</p>";
						str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res7.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
						str+="<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/news/" + res7.data[i].coverPicture + "' width='800' height='90'/>"
						str += "</div></div></div>";
						str += "</div>"
					}
					$("#newstitle").html(str);
				}
			}, "json");
//新闻类型
			$.get("../webmsg/newstype", function (res1) {
				if (res1.code == 201) {
					alert("失败")
				} else if (res1.code == 500) {
					alert("服务器忙");
				} else {
					var str = "";
					for (i = 0; i < res1.data.length; i++) {
						str += "<li><a href='javaScript:void(0)' class='sf-with-ul' onclick='selecttype(" + res1.data[i].id + ")'>" + res1.data[i].name + "</a></li>";
					}
					$("#newstype").html(str);
				}
			}, "json");


			//推荐文章
			$.get("../webmsg/recommend", function (res11) {
				if (res11.code == 201) {
					alert("失败")
				} else if (res11.code == 500) {
					alert("服务器忙");
				} else {
					console.log(res11)
					var str = "";
					for (i = 0; i < res11.data.length; i++) {
						str += "<li><div class=\"artl\"><a href='javaScript:void(0)' onclick='newscont(" + res11.data[i].id + ")'>\n" +
								"<p>" + res11.data[i].title + "</p></a>\n" +
								"\t\t \t<label>" + res11.data[i].publishTime + "</label>\n" +
								"\t\t \t\t\t\t\t\t</div><div class=\"artr\">\n" +
								"\t\t \t\t\t\t\t\t\t<a href=\"\" target=\"_blank\" id=\"admsg5\">\n" + "<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res11.data[i].coverPicture + "' width='800' height='90'/>" +
								"\t\t \t\t\t\t\t\t\t</a></div></li>   "
					}
					$("#recommend").html(str);

				}
			}, "json");


			//点击最多
			$.get("../webmsg/click", function (res12) {
				if (res12.code == 201) {
					alert("失败")
				} else if (res12.code == 500) {
					alert("服务器忙");
				} else {
					console.log(res12)
					var str = "";
					for (i = 0; i < res12.data.length; i++) {
						str += "\t<li><div class=\"artl\"><a href='javaScript:void(0)' onclick='newscont(" + res12.data[i].id + ")'>\n" +
								"\t\t\t\t\t\t\t\t<p>" + res12.data[i].title + "</p></a>\n" +
								"\t\t\t\t\t\t\t<label>" + res12.data[i].publishTime + "</label>\n" +
								"\t\t\t\t\t\t</div><div class=\"artr\">\n" +
								"\t\t\t\t\t\t\t<a href=\"\" target=\"_blank\"><img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res12.data[i].coverPicture + "' width='800' height='90'/></a></div></li>"
					}
					$("#click").html(str);

				}
			}, "json");

			//广告位显示
			//新闻类型
			$.get("../webmsg/admsg", function (res8) {
				if (res8.code == 201) {
					alert("失败")
				} else if (res8.code == 500) {
					alert("服务器忙");
				} else {
					console.log(res8)

					for (i = 0; i < res8.data.length; i++) {
						var str = "";
						str += "<a href=" + res8.data[i].url + ">";
						str += "<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/ad/" + res8.data[i].name + "' width='800' height='90'/>";
						str += "</a>";
						if (res8.data[i].position == 1) {
							$("#admsg1").html(str)
						} else if (res8.data[i].position == 2) {
							$("#admsg2").html(str)
						} else if (res8.data[i].position == 3) {
							$("#admsg3").html(str)
						} else if (res8.data[i].position == 4) {
							$("#admsg4").html(str)
						} else {
							alert("参数错误")
						}
					}
				}
			}, "json");


			//友情链接
			$.get("../webmsg/links", function (res2) {
				if (res2.code == 201) {
					alert("失败")
				} else if (res2.code == 500) {
					alert("服务器忙");
				} else {
					var str = "";
					for (i = 0; i < res2.data.length; i++) {
						str += "<a href='" + "https://www." + res2.data[i].linkUrl + "'>" + res2.data[i].linkName + "</a>"
					}
					$("#link").html(str)

				}
			}, "json");
		})

		//文章内容
		function selecttype(id) {
			if (id == 1) {
				$.get("../webmsg/newnewstypeid", function (res0) {
					console.log(res0.data)
					if (res0.code == 201) {
						alert("失败")
					} else if (res0.code == 500) {
						alert("服务器忙");
					} else {
						$("#type").html("最新推荐")
						var str = "";
						for (i = 0; i < res0.data.length; i++) {
							str += "<div class=\"lista\">"
							str += "<h3>";
							str += "<a href='javaScript:void(0)' onclick='newscont(" + res0.data[i].id + ")' id='title'>" + res0.data[i].title + "</a>"
							str += "</h3>";
							str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
							str += "<b>" + res0.data[i].publishTime + "</b>"
							str += " </div><div class=\"art_summary\">";
							str += "<p>" + res0.data[i].summary + "</p>";
							str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res0.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
							str+="<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/news/" + res0.data[i].coverPicture + "' width='800' height='90'/>"
							str += "</div></div></div>";
							str += "</div>"
						}
						$("#newstitle").html(str);
					}
				}, "json");
			} else {
				$.get("../webmsg/newstypeid", {id: id}, function (res5) {
					console.log(id)
					if (res5.code == 201) {
						alert("失败")
					} else if (res5.code == 500) {
						alert("服务器忙");
					} else {
						$("#type").html(res5.data[0].name)
						var str = "";
						for (i = 0; i < res5.data.length; i++) {
							str += "<div class=\"lista\">"
							str += "<h3>";
							str += "<a href='javaScript:void(0)' onclick='newscont(" + res5.data[i].id + ")' id='title'>" + res5.data[i].title + "</a>"
							str += "</h3>";
							str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
							str += "<b>" + res5.data[i].publishTime + "</b>"
							str += " </div><div class=\"art_summary\">";
							str += "<p>" + res5.data[i].summary + "</p>";
							str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res5.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
							str+="<img src='" + "http://127.0.0.1:8080/tomorrowNewsFiles/news/" + res5.data[i].coverPicture + "' width='800' height='90'/>"
							str += "</div></div></div>";
							str += "</div>"
						}
						$("#newstitle").html(str);
					}
				}, "json");
			}
		}

		//搜索
		function search() {
			$.get("../webmsg/search", $("#searchform").serialize(), function (res6) {
				console.log(res6.data)
				if (res6.code == 200) {
					console.log(res6.data)
					alert("登录成功")
					var str = "";
					for (i = 0; i < res6.data.length; i++) {
						str += "<div class=\"lista\">"
						str += "<h3>";
						str += "<a href='javaScript:void(0)' onclick='newscont(" +res6.data[i].id+ ")'  id='title'>" + res6.data[i].title + "</a>"
						str += "</h3>";
						str += "<div class=\"pov\"><div class=\"sview\"><div class=\"sviewl\"><div class=\"tittop\">";
						str += "<b>" + res6.data[i].publishTime + "</b>"
						str += " </div><div class=\"art_summary\">";
						str += "<p>" + res6.data[i].summary + "</p>";
						str += "</div><div class=\"footbar\"><i class=\"footbar-category\"><a href=\"\">互联网</a></i><i class=\"footbar-like\"><a href=\"javascript:;\">点击量" + res6.data[i].clickNum + "</a></i></div></div><div class=\"sviewr\">";
						str += "</div></div></div>";
						str += "</div>"
					}
					$("#newstitle").html(str);

				} else {
					alert(res6.msg)
				}
			}, "json");
		}

		function newscont(id) {
			//增加点击量
			console.log(id)
			$.get("../webmsg/newid", {id: id}, function (resu1) {
				if (resu1.code == 201) {
					alert("失败")
				} else if (resu1.code == 500) {
					alert("服务器忙");
				} else {
					console.log("dssdsd")
					console.log(resu1.data.clickNum);
					var rid = resu1.data.clickNum + 1;
					var aid = resu1.data.id
					console.log("rid")
					console.log(rid)
					$.post("../webmsg/clicknum", {aid: aid, rid: rid}, function (resu2) {
						if (resu2.code == 201) {
							alert("失败")
						} else if (resu2.code == 500) {
							alert("服务器忙");
						} else {
							location.assign("newsContent.html?id=" + id);

						}
					}, "json");
				}
			}, "json");

		}

		function picture(url) {
			console.log(url)
		}
	</script>
</head>
<body>
<div>
	<!-- 顶部 -->
	<div class="top">
		<div class="top_content">
			<div class="top_logo">
                <span id="logo1">
                </span>
			</div>
			<div class="advert" id="admsg1">

			</div>
			<div class="user" id="userMsg">
				<a href="../user/user_login.html">
					<button type="submit" class="login">登录</button>
				</a>
			</div>
			<div style="clear: left;"></div>
		</div>
	</div>
	<!-- 内容区 -->
	<div id="main_box">
		<div class="left">
			<div class="left-col">
				<div class="nav">
					<ul class="sf-menu sf-arrows" id="newstype">
					</ul>
				</div>
			</div>
		</div>
		<!--中间区域-->
		<div class="middle">
			<!---轮播内容-->
			<div class="gslider">
				<!-- 图片滑动 -->
				<div class="swiper-container swiper-container-initialized swiper-container-horizontal">
					<div class="swiper-wrapper">
						<div class="swiper-slide swiper-slide-active" style="width: 770px;">
							<a href="" id="admsg2">

							</a>
						</div>
					</div>
					<!-- 分页器 -->
					<div class="swiper-pagination"></div>
					<!-- 导航按钮 -->
					<div class="swiper-button-prev" tabindex="0" role="button" aria-label="Previous slide"></div>
					<div class="swiper-button-next" tabindex="0" role="button" aria-label="Next slide"></div>
					<span class="swiper-notification" aria-live="assertive" aria-atomic="true"></span></div>
			</div>
			<div class="sviewr"></div>

			<!--文章容器  文章列表开始-->
			<div class="recent-content">
				<h2><span id="type"></span></h2>
				<div>
					<div id="newstitle">
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="right">
		<div class="searchbox">
			<form id="searchform" method="get">
				<input type="search" name="searchname" class="search-input" value="" placeholder="请输入关键词"
					   autocomplete="off">
				<input type="button" class="search-submit" onclick="search()" value="搜索"></input>
			</form>
		</div>
		<!--广告图-->
		<div class="ali">
			<a href="" id="admsg3">

			</a>
		</div>
		<!--推荐文章-->
		<div class="sitebar-article">
			<h2><span>推荐文章</span></h2>
			<div class="sitebar-article-list">
				<ul id="recommend">
					<!--推荐文章列表-->


				</ul>
			</div>
		</div>

		<!--广告位-->
		<div class="ali">
			<a href="" id="admsg4">

			</a>
		</div>

		<!--点击最多的文章-->
		<div class="sitebar-article">
			<h2><span>点击最多的文章</span></h2>
			<div class="sitebar-article-list">
				<ul id="click">

				</ul>
			</div>
		</div>
	</div>
	<div style="clear: left;"></div>
	<!-- 底部友情链接,网站信息 -->
	<div class="main_bottom">
		<div class="main_bottom_link">
			<div class="main_bottom_link_title">友情链接</div>
			<div class="main_bottom_link_content" id="link">
			</div>
		</div>
		<div class="main_bottom_info" id="webmsg">
		</div>
	</div>
</div>
</div>
</body>
</html>
